package com.hl.mapper;

import com.hl.pojo.SystemUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SystemUserMapper {

    // 添加用户
    @Insert("insert into system_user (username, password, phone_number, salt) values (#{username}, #{password}, #{phoneNumber}, #{salt})")
    public Integer add(SystemUser systemUser);

    // 根据id删除用户
    @Update("update system_user set del = 1 where id = #{id}")
    public Integer del(Integer id);

    // 更新用户信息
    @Update("update system_user set username=#{username}, password=#{password}, phone_number=#{phoneNumber}, role=#{role} where id=#{id}")
    public Integer update(SystemUser systemUser);

    // 查询所有用户
    @Select("select * from system_user where del = 0")
    public List<SystemUser> findAll();

    // 根据用户名查询用户
    @Select("select * from system_user where username = #{username} and del = 0")
    public SystemUser findByUsername(String username);

    @Select("select * from system_user where phone_number=#{phoneNumber} and del = 0")
    public SystemUser findByPhoneNumber(String phoneNumber);

    // 根据id查询用户
    @Select("select * from system_user where id = #{id} and del = 0")
    public SystemUser findById(Integer id);
}